
//create by lwy 2017年9月25日11:13:00


var ajaxData = [100,0,0];
var ajaxData2 = [];
$.ajax({
    type: "POST",
    url: '/lowerC/shareTeam.json',
    dataType: "json",
    async : false,//给全局变量赋值
    data:{
        token:getItem('token'),
    },
    beforeSend:function(){
        $('<div class="loading"><img src="../phoneImg/jiazaizhong.gif"/></div>').appendTo($('.mui-content'));
    },
    success: function(data) {
        $('.loading').hide();
        if(data.code==1){
            if(data.datas.one.persons==0&&data.datas.two.persons==0&&data.datas.three.persons==0){
                $('.mui-content').empty();
                $('<div class="kong"><img src="../phoneImg/kong.png" alt="暂无数据"></div>').appendTo($('.mui-content'));
            }else{
                ajaxData2.push(data.datas.one.percentage*100);
                ajaxData2.push(data.datas.two.percentage*100);
                ajaxData2.push(data.datas.three.percentage*100);
                $('<div class="one"><span></span><b id="one">一级'+data.datas.one.persons+'人</b><a href="memberDetail_v2.html?grade=1" class="findMember">查看成员</a></div>\n' +
                    '        <div class="two"><span></span><b id="two">二级'+data.datas.two.persons+'人</b><a href="memberDetail_v2.html?grade=2" class="findMember">查看成员</a></div>\n' +
                    '        <div class="three"><span></span><b id="three">三级'+data.datas.three.persons+'人</b><a href="memberDetail_v2.html?grade=3" class="findMember">查看成员</a></div>').appendTo($('.memberBox'))
            }
        }
        if(data.code==-1){
            window.location.href="login.html"
        }
        if(data.code==0){
            mui.toast(data.msg);
        }

    }
});



$('#container3').highcharts({
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        backgroundColor: 'rgba(0,0,0,0)'//背景透明
    },
    credits:{
        enabled:false // 禁用版权信息
    },
    title: {
        text: null
    },
    tooltip: {

    },
    plotOptions: {
        pie: {
            size: '100%',
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                distance: -35,
                formatter: function() {
                    if (this.percentage > 4) return Highcharts.numberFormat(this.point.percentage, 1) +'%';
                },
                color: '#fff',
                style: {
                    fontWeight:0,
                    font: '20px Trebuchet MS, Verdana, sans-serif'
                }
            },
            showInLegend: false,
            colors: ['#68d7c6','#7b4e79','#f4675e'],//指定颜色
        },
        series: {
            states: {
                hover: {
                    enabled: false
                }
            }
        }
    },
    legend: {
        itemHoverStyle: {
            color: '#fff'
        },
        itemStyle : {
            'fontSize' : '20px',
            'color'    : '#768499',
            'fontWeight': '100'
        },
        layout: 'vertical',
        align: 'left',
        verticalAlign: 'middle',
        symbolHeight: 12,
        symbolWidth :12,
        symbolRadius :10,
        itemMarginBottom:10,
        itemWidth: 105,
        x: 10,
        y: 5,
        borderWidth: 0,
        labelFormatter: function () {
            return this.name + '&nbsp';
        },
        useHTML: true
    },
    series: [{
        type: 'pie',
        name: 'Browser share',
        borderWidth:0,
        data: ajaxData2
    }]
});

//分享流水
$('#flow').click(function () {
    $('#container3').hide();
    $('.memberBox').hide();
    $('#makeOrder').show();
    mui('#refreshContainer').pullRefresh().scrollTo(0, 0);//滚动到顶部
    mui('#refreshContainer').pullRefresh().refresh(true);
    if($('.mui-pull-caption').html()=='上拉显示更多'){
        $('.mui-pull-caption').html('');
    }
    $('#makeOrder').empty();
    $('#flow').addClass('active');
    $('#flow').find('.active-border').show();
    $('#team').removeClass('active');
    $('#team').find('.active-border').hide();
    page=0;
    doAjax();
})

$('#team').click(function () {
    $('#container3').show();
    $('.memberBox').show();
    $('#makeOrder').hide();
    mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
    $(this).addClass('active');
    $(this).find('.active-border').show();
    $(this).siblings().removeClass('active');
    $(this).siblings().find('.active-border').hide();
})


//上拉加载
mui.init({
    pullRefresh : {
        container:"#refreshContainer",//待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
        up : {
            contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
            contentnomore:'我是有底线的',//可选，请求完毕若没有更多数据时显示的提醒内容；
            callback :function(){
                setTimeout(function () {
                    var numResult = doAjax();
                    if (numResult < 10) {
                        mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
                    } else {
                        mui('#refreshContainer').pullRefresh().endPullupToRefresh(false);
                    }
                }, 1000);
            } //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
        }
    }
});

var num =0;

function doAjax() {
    page++;
    $.ajax({
        url:'/commissionC/getCommission.json',
        dataType:'json',
        type:'post',
        data:{
            token:getItem('token'),
            page:page,
        },
        beforeSend:function(){
            if(page==1){
                $('<div class="loading"><img src="../phoneImg/jiazaizhong.gif"/></div>').appendTo($('#makeOrder'));
            }
        },
        success:function(data){
            if(data.code==-1){
                window.location.href="login.html";
            }
            if(data.code==0){
                mui.toast(data.msg);
            }
            if(data.code==1){
                var data = data.datas.data;
                if(page==1){
                    $('#makeOrder').empty();
                    if(data.length==0){
                        mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
                        $('<div class="kong"><img src="../phoneImg/kong.png" alt="暂无数据"></div>').appendTo($('#makeOrder'));
                    }
                }
                for(var i=0;i<data.length;i++){
                    $('<div class="order-list">'+
                        '<div class="mui-clearfix">'+
                        '<div class="order-list-left"><span class="line"></span><b></b><span class="line line2"></span></div>'+
                        '<div class="order-list-sanjiao"></div>'+
                        '<div class="order-list-right">'+
                        '<span class="time">'+data[i].date+'</span><img src="../img/order-more.png"/><a class="detail" code="'+data[i].code+'">查看详情</a>'+
                        '<p class="line3"></p>'+
                        '<p class="two-line"><i class="money-sign">¥</i><span class="money">'+data[i].money+'</span></p>'+
                        '<p class="code">'+data[i].code+'</p>'+
                        '</div></div></div>').appendTo($('#makeOrder'))
                }
                num=data.length;
            }
        }
    })
    return num;
}

mui('body').on('tap','.detail',function () {
    var code= $(this).attr('code');
    window.location.href="share_detail.html?code="+code;
})

//
mui('body').on('tap','.findMember',function () {
    var href= $(this).attr('href');
    window.location.href=href;
})
